package com.ypinkj.app.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ypinkj.app.entity.*;
import com.ypinkj.app.mapper.*;
import com.ypinkj.app.utils.document.PdfDemo;
import com.ypinkj.app.utils.resultutils.Result;
import com.ypinkj.app.utils.resultutils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LF
 * @date 2020/10/15 - 15:46
 */
@Api(tags = "在线简历")
@RestController
@RequestMapping("/u-resume")
public class ResumePriewController {

    @Autowired
    UResumeJobhuntingMapper uResumeJobhuntingMapper;//求职意向
    @Autowired
    UResumeExperienceMapper resumeExperienceMapper;//项目经历
    @Autowired
    UResumeValuationMapper resumeValuationMapper;//自我评价
    @Autowired
    UResumeEducationMapper resumeEducationMapper;//教育背景
    @Autowired
    UResumeWorkMapper resumeWorkMapper;//工作经历
    @Autowired
    UResumeProgressMapper resumeProgressMapper;//个人特长
    @Autowired
    UResumeCertificateMapper resumeCertificateMapper;//技能证书
    @Autowired
    UResumeInfoMapper resumeInfoMapper;//个人信息

    @ApiOperation(value = "在线简历生成PDF")
    @GetMapping
    public Result createResume(String userid){
        List <List> arrayList = new ArrayList<>();//创建集合传参

        //求职意向
        LambdaQueryWrapper<UResumeJobhunting> wrapper7 = new LambdaQueryWrapper<>();
        wrapper7.eq(UResumeJobhunting::getUserid,userid);
        List<UResumeJobhunting> list7 = uResumeJobhuntingMapper.selectList(wrapper7);
        arrayList.add(0,list7);
        //项目经验
        LambdaQueryWrapper<UResumeExperience> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(UResumeExperience::getUserid,userid);
        List<UResumeExperience> list1 = resumeExperienceMapper.selectList(wrapper1);
        arrayList.add(1,list1);
        //教育经历
        LambdaQueryWrapper<UResumeEducation> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(UResumeEducation::getUserid,userid);
        List<UResumeEducation> list2 = resumeEducationMapper.selectList(wrapper2);
        arrayList.add(2,list2);
        //查询当前用户的工作经历
        LambdaQueryWrapper<UResumeWork> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UResumeWork::getUserid,userid);
        List<UResumeWork> list = resumeWorkMapper.selectList(wrapper);
        arrayList.add(3,list);
        //个人特长
        LambdaQueryWrapper<UResumeProgress> wrapper5 = new LambdaQueryWrapper<>();
        wrapper5.eq(UResumeProgress::getUserid,userid);
        List<UResumeProgress> list5 = resumeProgressMapper.selectList(wrapper5);
        arrayList.add(4,list5);
        //技能证书
        LambdaQueryWrapper<UResumeCertificate> wrapper4 = new LambdaQueryWrapper<>();
        wrapper4.eq(UResumeCertificate::getUserid,userid);
        List<UResumeCertificate> list4 = resumeCertificateMapper.selectList(wrapper4);
        arrayList.add(5,list4);
        //个人信息
        List<UResumeInfo> list3 = resumeInfoMapper.getList(userid);
        arrayList.add(6,list3);


        String s = PdfDemo.startCreate(arrayList);
        return s.equals(null) ? ResultUtil.errorMsg() : ResultUtil.success(s);
    }
}
